#ifndef _CRT_CLOCK_H_
#define _CRT_CLOCK_H_

#include <crt_core.hpp>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _clock_s _clock_t;

struct _clock_s {
#if (TARGET_OS == OS_WIN)
    LARGE_INTEGER freq;
#elif (TARGET_OS == OS_POSIX)
    // CLOCK_MONOTONIC_FAST==>
    // CLOCK_MONOTONIC_RAW ==>
    // CLOCK_MONOTONIC ==>
    clockid_t id;
#elif (TARGET_OS == OS_MACH)
    struct mach_timebase_info mach_timebase;
#elif (TARGET_OS == OS_UNIX)
    clockid_t id;
#else

#endif
    _mutex_t tmlock;
    struct timeval monotonic_clock;
    struct timeval last_clock;
};

int _clock_init(_clock_t* clock);
long get_clock_sec(_clock_t* clock);
long get_clock_usec(_clock_t* clock);
int get_clock(_clock_t* clock, struct timeval* tv);
int clock_adjust(_clock_t* clock, struct timeval* tv);
int clock_outputlog(_clock_t* clock);

#ifdef __cplusplus
}
#endif

#endif
